from django import forms
from django.core.exceptions import ValidationError

from .models import BWebtype, BGroup, BTrade, BProxyAddresses, BUniqueIndb, BLogAddresses, BSpiderType
from zhongbao_admin.models import User, GroupConfigEach
from .models_sqlalchemy import *
from public_modules import time_about

from public_modules.args_dict import dark_search, exact_search

add_config_message = '先上传配置,可自动填写'
config_id_message = '精准搜索，无法与其他字段联动'
channel_select_message = '可多个搜索，空格间隔'
search_mes_inexact = '模糊搜索,包含'


class ConfigEachForm(forms.Form):
    groups_name = forms.CharField(label='组名', max_length=30)
    users = forms.ModelMultipleChoiceField(label='选择配置人员', required=False,
                                           queryset=User.objects.filter(groups__name__contains='配置工程师'),
                                           widget=forms.CheckboxSelectMultiple()
                                           )


class ConfigGroupForm(forms.Form):
    groups = forms.ModelMultipleChoiceField(label='配置组', required=False,
                                            queryset=GroupConfigEach.objects.filter(),
                                            widget=forms.CheckboxSelectMultiple()
                                            )


def validate_repeat_times(val):
    if int(val) > 100:
        raise ValidationError('重复次数不能多于100')
    elif int(val) < 1:
        raise ValidationError('重复次数不能小于1')


class ConfigForm(forms.Form):
    webname = forms.CharField(label='网站名称', max_length=255, required=True, widget=forms.TextInput(attrs={
        "placeholder": add_config_message, "class": 'config-input', "readonly": "value",
    }))
    url = forms.CharField(label='网站域名', max_length=300, required=True, widget=forms.TextInput(attrs={
        "placeholder": add_config_message, "class": 'config-input', "readonly": "value",
    }))
    tags = forms.CharField(label='标签', max_length=200, required=False, widget=forms.TextInput(attrs={
        "class": 'config-input',
    }))
    intervaltime = forms.IntegerField(label='间隔时间', required=False, widget=forms.TextInput(attrs={
        "class": 'config-input', 'value': 0,
    }))
    repeat_times = forms.IntegerField(label='配置重复次数', required=False, widget=forms.NumberInput(attrs={
        "class": 'config-input', 'value': 1, 'max': 100, 'min': 1
    }), help_text='重复次数不能小于1,不能大于100！', validators=[validate_repeat_times, ], )
    gid = forms.ModelChoiceField(label='所属分组(可搜索)', widget=forms.Select(attrs={
        "class": 'config-input', 'title': '启用状态无法更换分组！'
    }), queryset=BGroup.objects.real_group().order_by('groupname'), required=False)
    tid = forms.ModelChoiceField(label='行业类型', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BTrade.objects.all().order_by('id'), required=False)
    webtype = forms.ModelChoiceField(label='数据类型', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BWebtype.objects.all().order_by('id'), required=False)
    proxy_addresses_id = forms.ModelChoiceField(label='代理地址', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BProxyAddresses.objects.all().order_by('id'), required=False)
    # datasourcetype = forms.ChoiceField(label='数据来源', widget=forms.Select(attrs={
    #     "class": 'config-input',
    # }), choices=[(0, '----')] + list(sqlalchemy_session.query(DataSourceType.KD_ID, DataSourceType.KK_DATASOURCETYPE)),
    #                                    required=False)
    # datasourcetype = forms.IntegerField(label='数据来源', widget=forms.Select(attrs={
    #     "class": 'config-input',
    # }, choices=[(0, '----')] + list(sqlalchemy_session.query(DataSourceType.KD_ID, DataSourceType.KK_DATASOURCETYPE))),
    #                                    required=False)
    uig = forms.ModelChoiceField(label='入库去重', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BUniqueIndb.objects.all().order_by('id'), required=False)
    log_addresses_id = forms.ModelChoiceField(label='日志地址', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BLogAddresses.objects.all().order_by('id'), required=False)
    # is_agent = forms.ChoiceField(label='是否代理', widget=forms.Select(attrs={
    #     "class": 'config-input',
    # }), choices=[(2, '默认'), (0, '否'), (1, '是')], required=False)
    country = forms.ChoiceField(label="国家或地区", widget=forms.Select(attrs={"class": 'config-input'}),
                                required=False, choices=[(None, '--------'), ('AL', '阿尔巴尼亚'), ('DZ', '阿尔及利亚'),
                                                         ('AF', '阿富汗'), ('AR', '阿根廷'), ('AE', '阿拉伯联合酋长国'),
                                                         ('AW', '阿鲁巴'), ('OM', '阿曼'), ('AZ', '阿塞拜疆'), ('EG', '埃及'),
                                                         ('ET', '埃塞俄比亚'), ('IE', '爱尔兰'), ('EE', '爱沙尼亚'),
                                                         ('AD', '安道尔'), ('AO', '安哥拉'), ('AI', '安圭拉岛'),
                                                         ('AG', '安提瓜和巴布达'), ('AT', '奥地利'), ('AX', '奥兰岛'),
                                                         ('AU', '澳大利亚'), ('MO', '澳门特别行政区'), ('BB', '巴巴多斯'),
                                                         ('PG', '巴布亚新几内亚'), ('BS', '巴哈马'), ('PK', '巴基斯坦'),
                                                         ('PY', '巴拉圭'), ('PS', '巴勒斯坦民族权力机构'), ('BH', '巴林'),
                                                         ('PA', '巴拿马'), ('BR', '巴西'), ('BY', '白俄罗斯'), ('BM', '百慕大群岛'),
                                                         ('BG', '保加利亚'), ('MP', '北马里亚纳群岛'), ('BJ', '贝宁'),
                                                         ('BE', '比利时'), ('IS', '冰岛'), ('PR', '波多黎各'), ('PL', '波兰'),
                                                         ('BA', '波斯尼亚和黑塞哥维那'), ('BO', '玻利维亚'), ('BZ', '伯利兹'),
                                                         ('BW', '博茨瓦纳'), ('BQ', '博内尔'), ('BT', '不丹'), ('BF', '布基纳法索'),
                                                         ('BI', '布隆迪'), ('BV', '布韦岛'), ('KP', '朝鲜'), ('GQ', '赤道几内亚'),
                                                         ('DK', '丹麦'), ('DE', '德国'), ('TL', '东帝汶'), ('TG', '多哥'),
                                                         ('DO', '多米尼加共和国'), ('DM', '多米尼克'), ('RU', '俄罗斯'),
                                                         ('EC', '厄瓜多尔'), ('ER', '厄立特里亚'), ('FR', '法国'), ('FO', '法罗群岛'),
                                                         ('PF', '法属波利尼西亚'), ('GF', '法属圭亚那'), ('TF', '法属南极地区'),
                                                         ('VA', '梵蒂冈城'), ('PH', '菲律宾'), ('FJ', '斐济群岛'), ('FI', '芬兰'),
                                                         ('CV', '佛得角'), ('FK', '福克兰群岛(马尔维纳斯群岛)'), ('GM', '冈比亚'),
                                                         ('CD', '刚果(DRC)'), ('CG', '刚果共和国'), ('CO', '哥伦比亚'),
                                                         ('CR', '哥斯达黎加'), ('GG', '格恩西岛'), ('GD', '格林纳达'),
                                                         ('GL', '格陵兰'), ('GE', '格鲁吉亚'), ('CU', '古巴'), ('GP', '瓜德罗普岛'),
                                                         ('GU', '关岛'), ('GY', '圭亚那'), ('KZ', '哈萨克斯坦'), ('HT', '海地'),
                                                         ('KR', '韩国'), ('NL', '荷兰'), ('HM', '赫德和麦克唐纳群岛'),
                                                         ('ME', '黑山共和国'), ('HN', '洪都拉斯'), ('KI', '基里巴斯'), ('DJ', '吉布提'),
                                                         ('KG', '吉尔吉斯斯坦'), ('GN', '几内亚'), ('GW', '几内亚比绍'),
                                                         ('CA', '加拿大'), ('GH', '加纳'), ('GA', '加蓬'), ('KH', '柬埔寨'),
                                                         ('CZ', '捷克共和国'), ('ZW', '津巴布韦'), ('CM', '喀麦隆'), ('QA', '卡塔尔'),
                                                         ('KY', '开曼群岛'), ('CC', '科科斯群岛(基灵群岛)'), ('KM', '科摩罗联盟'),
                                                         ('CI', '科特迪瓦共和国'), ('KW', '科威特'), ('HR', '克罗地亚'),
                                                         ('KE', '肯尼亚'), ('CK', '库可群岛'), ('CW', '库拉索'), ('LV', '拉脱维亚'),
                                                         ('LS', '莱索托'), ('LA', '老挝'), ('LB', '黎巴嫩'), ('LT', '立陶宛'),
                                                         ('LR', '利比里亚'), ('LY', '利比亚'), ('LI', '列支敦士登'),
                                                         ('RE', '留尼汪岛'), ('LU', '卢森堡'), ('RW', '卢旺达'), ('RO', '罗马尼亚'),
                                                         ('MG', '马达加斯加'), ('IM', '马恩岛'), ('MV', '马尔代夫'), ('MT', '马耳他'),
                                                         ('MW', '马拉维'), ('MY', '马来西亚'), ('ML', '马里'),
                                                         ('MK', '马其顿, 前南斯拉夫共和国'), ('MH', '马绍尔群岛'), ('MQ', '马提尼克岛'),
                                                         ('YT', '马约特岛'), ('MU', '毛里求斯'), ('MR', '毛利塔尼亚'), ('US', '美国'),
                                                         ('AS', '美属萨摩亚'), ('UM', '美属外岛'), ('VI', '美属维尔京群岛'),
                                                         ('MN', '蒙古'),
                                                         ('MS', '蒙特塞拉特'), ('BD', '孟加拉国'), ('PE', '秘鲁'),
                                                         ('FM', '密克罗尼西亚'),
                                                         ('MM', '缅甸'), ('MD', '摩尔多瓦'), ('MA', '摩洛哥'), ('MC', '摩纳哥'),
                                                         ('MZ', '莫桑比克'),
                                                         ('MX', '墨西哥'), ('NA', '纳米比亚'), ('ZA', '南非'), ('AQ', '南极洲'),
                                                         ('GS', '南乔治亚和南德桑威奇群岛'), ('NR', '瑙鲁'), ('NP', '尼泊尔'),
                                                         ('NI', '尼加拉瓜'), ('NE', '尼日尔'), ('NG', '尼日利亚'), ('NU', '纽埃'),
                                                         ('NO', '挪威'), ('NF', '诺福克岛'), ('PW', '帕劳群岛'), ('PN', '皮特凯恩群岛'),
                                                         ('PT', '葡萄牙'), ('JP', '日本'), ('SE', '瑞典'), ('CH', '瑞士'),
                                                         ('SV', '萨尔瓦多'),
                                                         ('WS', '萨摩亚'), ('RS', '塞尔维亚共和国'), ('SL', '塞拉利昂'),
                                                         ('SN', '塞内加尔'),
                                                         ('CY', '塞浦路斯'), ('SC', '塞舌尔'), ('XS', '沙巴岛'), ('SA', '沙特阿拉伯'),
                                                         ('BL', '圣巴泰勒米岛'), ('CX', '圣诞岛'), ('ST', '圣多美和普林西比'),
                                                         ('SH', '圣赫勒拿岛'),
                                                         ('KN', '圣基茨和尼维斯'), ('LC', '圣卢西亚'), ('MF', '法属圣马丁岛'),
                                                         ('SX', '荷属圣马丁岛'), ('SM', '圣马力诺'), ('PM', '圣皮埃尔岛和密克隆岛'),
                                                         ('VC', '圣文森特和格林纳丁斯'), ('XE', '圣尤斯特歇斯岛'), ('LK', '斯里兰卡'),
                                                         ('SK', '斯洛伐克'), ('SI', '斯洛文尼亚'), ('SZ', '斯威士兰'), ('SD', '苏丹'),
                                                         ('SR', '苏里南'), ('SB', '所罗门群岛'), ('SO', '索马里'), ('TJ', '塔吉克斯坦'),
                                                         ('TW', '台湾'), ('TH', '泰国'), ('TZ', '坦桑尼亚'), ('TO', '汤加'),
                                                         ('TC', '特克斯和凯科斯群岛'), ('TT', '特立尼达和多巴哥'), ('TN', '突尼斯'),
                                                         ('TV', '图瓦卢'), ('TR', '土耳其'), ('TM', '土库曼斯坦'), ('TK', '托克劳'),
                                                         ('WF', '瓦利斯和富图纳'), ('VU', '瓦努阿图'), ('GT', '危地马拉'),
                                                         ('VG', '维尔京群岛(英属)'), ('VE', '委内瑞拉'), ('BN', '文莱'),
                                                         ('UG', '乌干达'),
                                                         ('UA', '乌克兰'), ('UY', '乌拉圭'), ('UZ', '乌兹别克斯坦'), ('ES', '西班牙'),
                                                         ('GR', '希腊'), ('HK', '香港特别行政区'), ('SG', '新加坡'),
                                                         ('NC', '新喀里多尼亚'),
                                                         ('NZ', '新西兰'), ('HU', '匈牙利'), ('SY', '叙利亚'), ('JM', '牙买加'),
                                                         ('AM', '亚美尼亚'),
                                                         ('SJ', '扬马延岛'), ('YE', '也门'), ('IQ', '伊拉克'), ('IR', '伊朗'),
                                                         ('IL', '以色列'),
                                                         ('IT', '意大利'), ('IN', '印度'), ('ID', '印度尼西亚'), ('UK', '英国'),
                                                         ('IO', '英属印度洋领地'),
                                                         ('JO', '约旦'), ('VN', '越南'), ('ZM', '赞比亚'), ('JE', '泽西'),
                                                         ('TD', '乍得'),
                                                         ('GI', '直布罗陀'), ('CL', '智利'), ('CF', '中非共和国'), ('CN', '中国')
                                                         ])
    language = forms.ChoiceField(label="语言", widget=forms.Select(attrs={"class": 'config-input'}),
                                 required=False, choices=[(None, '--------'), ("zh", "中文"), ("en", "英语"), ("jp", "日语"),
                                                          ("kor", "韩语"), ("pt", "葡萄牙语"), ("fra", "法语"),
                                                          ("spa", "西班牙语"), ("de", "德语"), ("it", "意大利语"),
                                                          ("ru", "俄语"), ("th", "泰语"), ("ara", "阿拉伯语"),
                                                          ("yue", "粤语"), ("wyw", "文言文"), ("nl", "荷兰语"),
                                                          ("el", "希腊语"), ("cht", "中文繁体"), ("hu", "匈牙利语"),
                                                          ('slo', '斯洛文尼亚语'), ('swe', '瑞典语'), ('rom', '罗马尼亚语'),
                                                          ('cs', '捷克语'),
                                                          ('fin', '芬兰语'), ('dan', '丹麦语'), ('pl', '波兰语'),
                                                          ('bul', '保加利亚语'),
                                                          ('est', '爱沙尼亚语'), ('vie', '越南语')
                                                          ])

    is_agent = forms.IntegerField(label='是否代理', widget=forms.Select(attrs={
        "class": 'config-input',
    }, choices=[(2, '默认'), (0, '否'), (1, '是')], ), required=False)


class ConfigSelectForm(forms.Form):
    author = forms.CharField(label='上传人', max_length=200, required=None, widget=forms.TextInput(
        attrs={"class": 'config-input', "placeholder": search_mes_inexact, }
    ))
    webname = forms.CharField(label='网站名称', max_length=30, required=False, widget=forms.TextInput(
        attrs={"class": 'config-input', "placeholder": search_mes_inexact, }
    ))
    url = forms.CharField(label='网站域名', max_length=200, required=False, widget=forms.TextInput(
        attrs={"class": 'config-input', "placeholder": search_mes_inexact, }
    ))
    tags = forms.CharField(label='标签', max_length=200, required=False, widget=forms.TextInput(attrs={
        "class": 'config-input', "placeholder": search_mes_inexact,
    }))
    gid = forms.ModelChoiceField(label='所属分组', widget=forms.Select(attrs={
        "class": 'config-input',
    }), required=False, queryset=BGroup.objects.real_group().order_by('groupname'))

    tid = forms.ModelChoiceField(label='行业类型', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BTrade.objects.all().order_by('id'), required=False)
    webtype = forms.ModelChoiceField(label='数据类型', widget=forms.Select(attrs={
        "class": 'config-input',
    }), required=False, queryset=BWebtype.objects.all())
    channelname = forms.CharField(label='频道名称', max_length=30, required=False, widget=forms.TextInput(
        attrs={"placeholder": channel_select_message, "class": 'config-input', }
    ))
    channelurl = forms.CharField(label='频道url', max_length=200, required=False, widget=forms.TextInput(
        attrs={"placeholder": channel_select_message, "class": 'config-input', }
    ))

    proxy_addresses_id = forms.ModelChoiceField(label='代理地址', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BProxyAddresses.objects.all().order_by('id'), required=False)
    # datasourcetype = forms.ChoiceField(label='数据来源', widget=forms.Select(attrs={
    #     "class": 'config-input',
    # }), choices=[(None, '----')] + list(sqlalchemy_session.query(DataSourceType.KD_ID, DataSourceType.KK_DATASOURCETYPE)),
    #                                    required=False)
    uig = forms.ModelChoiceField(label='入库去重', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BUniqueIndb.objects.all().order_by('id'), required=False)
    log_addresses_id = forms.ModelChoiceField(label='日志地址', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BLogAddresses.objects.all().order_by('id'), required=False)
    is_agent = forms.ChoiceField(label='是否代理', widget=forms.Select(attrs={
        "class": 'config-input',
    }), choices=[(None, '--------'), (2, '默认'), (0, '否'), (1, '是')], required=False)
    config_flag = forms.ChoiceField(label='配置类型', widget=forms.Select(attrs={
        "class": 'config-input',
    }), required=False, choices=[(4, '--------'), (0, '普通配置'), (1, '客户端'), (2, 'chrome插件'), (3, 'web可视')])
    country = forms.ChoiceField(label="国家或地区", widget=forms.Select(attrs={"class": 'config-input'}),
                                required=False, choices=[(None, '--------'), ('AL', '阿尔巴尼亚'), ('DZ', '阿尔及利亚'),
                                                         ('AF', '阿富汗'), ('AR', '阿根廷'), ('AE', '阿拉伯联合酋长国'),
                                                         ('AW', '阿鲁巴'), ('OM', '阿曼'), ('AZ', '阿塞拜疆'), ('EG', '埃及'),
                                                         ('ET', '埃塞俄比亚'), ('IE', '爱尔兰'), ('EE', '爱沙尼亚'),
                                                         ('AD', '安道尔'), ('AO', '安哥拉'), ('AI', '安圭拉岛'),
                                                         ('AG', '安提瓜和巴布达'), ('AT', '奥地利'), ('AX', '奥兰岛'),
                                                         ('AU', '澳大利亚'), ('MO', '澳门特别行政区'), ('BB', '巴巴多斯'),
                                                         ('PG', '巴布亚新几内亚'), ('BS', '巴哈马'), ('PK', '巴基斯坦'),
                                                         ('PY', '巴拉圭'), ('PS', '巴勒斯坦民族权力机构'), ('BH', '巴林'),
                                                         ('PA', '巴拿马'), ('BR', '巴西'), ('BY', '白俄罗斯'), ('BM', '百慕大群岛'),
                                                         ('BG', '保加利亚'), ('MP', '北马里亚纳群岛'), ('BJ', '贝宁'),
                                                         ('BE', '比利时'), ('IS', '冰岛'), ('PR', '波多黎各'), ('PL', '波兰'),
                                                         ('BA', '波斯尼亚和黑塞哥维那'), ('BO', '玻利维亚'), ('BZ', '伯利兹'),
                                                         ('BW', '博茨瓦纳'), ('BQ', '博内尔'), ('BT', '不丹'), ('BF', '布基纳法索'),
                                                         ('BI', '布隆迪'), ('BV', '布韦岛'), ('KP', '朝鲜'), ('GQ', '赤道几内亚'),
                                                         ('DK', '丹麦'), ('DE', '德国'), ('TL', '东帝汶'), ('TG', '多哥'),
                                                         ('DO', '多米尼加共和国'), ('DM', '多米尼克'), ('RU', '俄罗斯'),
                                                         ('EC', '厄瓜多尔'), ('ER', '厄立特里亚'), ('FR', '法国'), ('FO', '法罗群岛'),
                                                         ('PF', '法属波利尼西亚'), ('GF', '法属圭亚那'), ('TF', '法属南极地区'),
                                                         ('VA', '梵蒂冈城'), ('PH', '菲律宾'), ('FJ', '斐济群岛'), ('FI', '芬兰'),
                                                         ('CV', '佛得角'), ('FK', '福克兰群岛(马尔维纳斯群岛)'), ('GM', '冈比亚'),
                                                         ('CD', '刚果(DRC)'), ('CG', '刚果共和国'), ('CO', '哥伦比亚'),
                                                         ('CR', '哥斯达黎加'), ('GG', '格恩西岛'), ('GD', '格林纳达'),
                                                         ('GL', '格陵兰'), ('GE', '格鲁吉亚'), ('CU', '古巴'), ('GP', '瓜德罗普岛'),
                                                         ('GU', '关岛'), ('GY', '圭亚那'), ('KZ', '哈萨克斯坦'), ('HT', '海地'),
                                                         ('KR', '韩国'), ('NL', '荷兰'), ('HM', '赫德和麦克唐纳群岛'),
                                                         ('ME', '黑山共和国'), ('HN', '洪都拉斯'), ('KI', '基里巴斯'), ('DJ', '吉布提'),
                                                         ('KG', '吉尔吉斯斯坦'), ('GN', '几内亚'), ('GW', '几内亚比绍'),
                                                         ('CA', '加拿大'), ('GH', '加纳'), ('GA', '加蓬'), ('KH', '柬埔寨'),
                                                         ('CZ', '捷克共和国'), ('ZW', '津巴布韦'), ('CM', '喀麦隆'), ('QA', '卡塔尔'),
                                                         ('KY', '开曼群岛'), ('CC', '科科斯群岛(基灵群岛)'), ('KM', '科摩罗联盟'),
                                                         ('CI', '科特迪瓦共和国'), ('KW', '科威特'), ('HR', '克罗地亚'),
                                                         ('KE', '肯尼亚'), ('CK', '库可群岛'), ('CW', '库拉索'), ('LV', '拉脱维亚'),
                                                         ('LS', '莱索托'), ('LA', '老挝'), ('LB', '黎巴嫩'), ('LT', '立陶宛'),
                                                         ('LR', '利比里亚'), ('LY', '利比亚'), ('LI', '列支敦士登'),
                                                         ('RE', '留尼汪岛'), ('LU', '卢森堡'), ('RW', '卢旺达'), ('RO', '罗马尼亚'),
                                                         ('MG', '马达加斯加'), ('IM', '马恩岛'), ('MV', '马尔代夫'), ('MT', '马耳他'),
                                                         ('MW', '马拉维'), ('MY', '马来西亚'), ('ML', '马里'),
                                                         ('MK', '马其顿, 前南斯拉夫共和国'), ('MH', '马绍尔群岛'), ('MQ', '马提尼克岛'),
                                                         ('YT', '马约特岛'), ('MU', '毛里求斯'), ('MR', '毛利塔尼亚'), ('US', '美国'),
                                                         ('AS', '美属萨摩亚'), ('UM', '美属外岛'), ('VI', '美属维尔京群岛'),
                                                         ('MN', '蒙古'),
                                                         ('MS', '蒙特塞拉特'), ('BD', '孟加拉国'), ('PE', '秘鲁'),
                                                         ('FM', '密克罗尼西亚'),
                                                         ('MM', '缅甸'), ('MD', '摩尔多瓦'), ('MA', '摩洛哥'), ('MC', '摩纳哥'),
                                                         ('MZ', '莫桑比克'),
                                                         ('MX', '墨西哥'), ('NA', '纳米比亚'), ('ZA', '南非'), ('AQ', '南极洲'),
                                                         ('GS', '南乔治亚和南德桑威奇群岛'), ('NR', '瑙鲁'), ('NP', '尼泊尔'),
                                                         ('NI', '尼加拉瓜'), ('NE', '尼日尔'), ('NG', '尼日利亚'), ('NU', '纽埃'),
                                                         ('NO', '挪威'), ('NF', '诺福克岛'), ('PW', '帕劳群岛'), ('PN', '皮特凯恩群岛'),
                                                         ('PT', '葡萄牙'), ('JP', '日本'), ('SE', '瑞典'), ('CH', '瑞士'),
                                                         ('SV', '萨尔瓦多'),
                                                         ('WS', '萨摩亚'), ('RS', '塞尔维亚共和国'), ('SL', '塞拉利昂'),
                                                         ('SN', '塞内加尔'),
                                                         ('CY', '塞浦路斯'), ('SC', '塞舌尔'), ('XS', '沙巴岛'), ('SA', '沙特阿拉伯'),
                                                         ('BL', '圣巴泰勒米岛'), ('CX', '圣诞岛'), ('ST', '圣多美和普林西比'),
                                                         ('SH', '圣赫勒拿岛'),
                                                         ('KN', '圣基茨和尼维斯'), ('LC', '圣卢西亚'), ('MF', '法属圣马丁岛'),
                                                         ('SX', '荷属圣马丁岛'), ('SM', '圣马力诺'), ('PM', '圣皮埃尔岛和密克隆岛'),
                                                         ('VC', '圣文森特和格林纳丁斯'), ('XE', '圣尤斯特歇斯岛'), ('LK', '斯里兰卡'),
                                                         ('SK', '斯洛伐克'), ('SI', '斯洛文尼亚'), ('SZ', '斯威士兰'), ('SD', '苏丹'),
                                                         ('SR', '苏里南'), ('SB', '所罗门群岛'), ('SO', '索马里'), ('TJ', '塔吉克斯坦'),
                                                         ('TW', '台湾'), ('TH', '泰国'), ('TZ', '坦桑尼亚'), ('TO', '汤加'),
                                                         ('TC', '特克斯和凯科斯群岛'), ('TT', '特立尼达和多巴哥'), ('TN', '突尼斯'),
                                                         ('TV', '图瓦卢'), ('TR', '土耳其'), ('TM', '土库曼斯坦'), ('TK', '托克劳'),
                                                         ('WF', '瓦利斯和富图纳'), ('VU', '瓦努阿图'), ('GT', '危地马拉'),
                                                         ('VG', '维尔京群岛(英属)'), ('VE', '委内瑞拉'), ('BN', '文莱'),
                                                         ('UG', '乌干达'),
                                                         ('UA', '乌克兰'), ('UY', '乌拉圭'), ('UZ', '乌兹别克斯坦'), ('ES', '西班牙'),
                                                         ('GR', '希腊'), ('HK', '香港特别行政区'), ('SG', '新加坡'),
                                                         ('NC', '新喀里多尼亚'),
                                                         ('NZ', '新西兰'), ('HU', '匈牙利'), ('SY', '叙利亚'), ('JM', '牙买加'),
                                                         ('AM', '亚美尼亚'),
                                                         ('SJ', '扬马延岛'), ('YE', '也门'), ('IQ', '伊拉克'), ('IR', '伊朗'),
                                                         ('IL', '以色列'),
                                                         ('IT', '意大利'), ('IN', '印度'), ('ID', '印度尼西亚'), ('UK', '英国'),
                                                         ('IO', '英属印度洋领地'),
                                                         ('JO', '约旦'), ('VN', '越南'), ('ZM', '赞比亚'), ('JE', '泽西'),
                                                         ('TD', '乍得'),
                                                         ('GI', '直布罗陀'), ('CL', '智利'), ('CF', '中非共和国'), ('CN', '中国')
                                                         ])
    language = forms.ChoiceField(label="语言", widget=forms.Select(attrs={"class": 'config-input'}),
                                 required=False, choices=[(None, '--------'), ("zh", "中文"), ("en", "英语"), ("jp", "日语"),
                                                          ("kor", "韩语"), ("pt", "葡萄牙语"), ("fra", "法语"),
                                                          ("spa", "西班牙语"), ("de", "德语"), ("it", "意大利语"),
                                                          ("ru", "俄语"), ("th", "泰语"), ("ara", "阿拉伯语"),
                                                          ("yue", "粤语"), ("wyw", "文言文"), ("nl", "荷兰语"),
                                                          ("el", "希腊语"), ("cht", "中文繁体"), ("hu", "匈牙利语"),
                                                          ('slo', '斯洛文尼亚语'), ('swe', '瑞典语'), ('rom', '罗马尼亚语'),
                                                          ('cs', '捷克语'),
                                                          ('fin', '芬兰语'), ('dan', '丹麦语'), ('pl', '波兰语'),
                                                          ('bul', '保加利亚语'),
                                                          ('est', '爱沙尼亚语'), ('vie', '越南语')
                                                          ])


class CheckConfigForm(forms.Form):
    check_result = forms.ChoiceField(label='审核结果', required=True, widget=forms.Select(
        attrs={"class": 'config-input', }
    ), choices=[(1, '通过'), (0, '不通过',), ])
    check_comments = forms.CharField(label='审核备注', max_length=300, required=None, widget=forms.TextInput(
        attrs={"class": 'config-input', }
    ))
    check_score = forms.DecimalField(label='绩效分数', decimal_places=1, max_digits=2, required=True,
                                     widget=forms.TextInput(
                                         attrs={"class": 'config-input', 'maxlength': '4'}
                                     ), help_text='评分范围-10-10，接受1位小数(1.5)')


class VisualConfigForm(forms.Form):
    webname = forms.CharField(label='网站名称', max_length=30, required=True, widget=forms.TextInput(attrs={
        "placeholder": add_config_message, "class": 'config-input',
    }))
    url = forms.CharField(label='网站域名', max_length=200, required=True, widget=forms.TextInput(attrs={
        "placeholder": add_config_message, "class": 'config-input',
    }))


class VisualConfigSelectForm(forms.Form):
    author = forms.CharField(label='上传人', max_length=200, required=None, widget=forms.TextInput(
        attrs={"class": 'config-input', }
    ))
    webname = forms.CharField(label='网站名称', max_length=30, required=False, widget=forms.TextInput(
        attrs={"class": 'config-input', }
    ))
    url = forms.CharField(label='网站域名', max_length=200, required=False, widget=forms.TextInput(
        attrs={"class": 'config-input', }
    ))


class BspiderSelectForm(forms.Form):
    id = forms.CharField(label='爬虫id', max_length=10, required=False, widget=forms.TextInput(attrs={
        "placeholder": exact_search, "class": 'config-input',
    }))
    host_id = forms.CharField(label='主机ip', max_length=100, required=False, widget=forms.TextInput(attrs={
        "placeholder": dark_search, "class": 'config-input',
    }))
    cid = forms.CharField(label='配置ID', max_length=100, required=False, widget=forms.TextInput(attrs={
        "class": 'config-input', "placeholder": exact_search,
    }))
    savename = forms.CharField(label='文件名称', max_length=200, required=False, widget=forms.TextInput(attrs={
        "class": 'config-input', "placeholder": exact_search,
    }))
    webname = forms.CharField(label='网站名称', max_length=100, required=False, widget=forms.TextInput(attrs={
        "class": 'config-input', "placeholder": exact_search,
    }))
    gid = forms.ModelChoiceField(label='所属分组', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BGroup.objects.real_group().order_by('groupname'), required=False)
    status = forms.ChoiceField(label='状态', widget=forms.Select(attrs={
        "class": 'config-input',
    }), choices=[(None, '------'), (0, '顺序'), (1, '指定')], required=False)
    spider_type = forms.ModelChoiceField(label='爬虫分类', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BSpiderType.objects.all().order_by('id'), required=False)
    checkstatus = forms.ChoiceField(label='是否监测', widget=forms.Select(attrs={
        "class": 'config-input',
    }), choices=[(None, '------'), (0, '否'), (1, '是')], required=False)
    is_use = forms.ChoiceField(label='是否使用', widget=forms.Select(attrs={
        "class": 'config-input',
    }), choices=[(None, '------'), (0, '未使用'), ], required=False)


class NoGidBspiderSelectForm(forms.Form):
    id = forms.CharField(label='配置id', max_length=10, required=False, widget=forms.TextInput(attrs={
        "placeholder": exact_search, "class": 'config-input',
    }))
    savename = forms.CharField(label='文件名称', max_length=200, required=False, widget=forms.TextInput(attrs={
        "class": 'config-input', "placeholder": exact_search,
    }))


class BspiderEmptyDelForm(forms.Form):
    spider_type = forms.ModelChoiceField(label='爬虫分类', widget=forms.Select(attrs={
        "class": 'config-input',
    }), queryset=BSpiderType.objects.all().order_by('id'), required=False)


class TaskSearchForm(forms.Form):
    # id = forms.IntegerField(required=False, label='任务ID', widget=forms.TextInput(attrs={"class": "config-input"}))
    number = forms.CharField(max_length=256, required=False, label='任务编号',
                             widget=forms.TextInput(attrs={"class": "config-input"}))

    project_id = forms.IntegerField(required=False, label='项目ID',
                                    widget=forms.TextInput(attrs={"class": "config-input"}))
    site_name = forms.CharField(max_length=256, required=False, label='网站名称',
                                widget=forms.TextInput(attrs={"class": "config-input"}))
    site_url = forms.CharField(max_length=256, required=False, label="网站URL",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    username = forms.CharField(max_length=256, required=False, label="用户名",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    site_type = forms.IntegerField(required=False, label="网站类型",
                                   widget=forms.TextInput(attrs={"class": "config-input"}))
    domain = forms.CharField(max_length=128, required=False, label="域名",
                             widget=forms.TextInput(attrs={"class": "config-input"}))
    ctime = forms.IntegerField(required=False, label="录入时间",
                               widget=forms.TextInput(attrs={"class": "config-input", "id": "test3"}))
    # receive_flag = forms.IntegerField(required=False, label="领取时间",
    #                                   widget=forms.TextInput(attrs={"class": "config-input", "id": "test4"}))
    submit_flag = forms.IntegerField(required=False, label="提交时间",
                                     widget=forms.TextInput(attrs={"class": "config-input", "id": "test5"}))
    # allocation_flag = forms.IntegerField(required=False, label="分配时间",
    #                                      widget=forms.TextInput(attrs={"class": "config-input", "id": "test1"}))
    # process_type = forms.IntegerField(required=False, label="分配代码",
    #                                   widget=forms.TextInput(attrs={"class": "config-input"}))
    # note = forms.CharField(max_length=256, required=False, label="任务备注",
    #                        widget=forms.TextInput(attrs={"class": "config-input"}))
    qualified_passed_flag = forms.IntegerField(required=False, label="通过时间",
                                               widget=forms.TextInput(attrs={"class": "config-input", "id": "test2"}))
    unqualified_flag = forms.IntegerField(required=False, label="不合格时间",
                                               widget=forms.TextInput(attrs={"class": "config-input", "id": "test4"}))
    finish_flag = forms.IntegerField(required=False, label="合格时间",
                                               widget=forms.TextInput(attrs={"class": "config-input", "id": "test1"}))
    # lang = forms.CharField(max_length=32, required=False, label="网站语言",
    #                        widget=forms.TextInput(attrs={"class": "config-input"}))
    # description = forms.CharField(max_length=256, required=False, label="任务描述",
    #                               widget=forms.TextInput(attrs={"class": "config-input"}))
    # num_each_page = forms.ChoiceField(label="每页展示条数", widget=forms.Select(attrs={"class": 'config-input'}),
    #                         required=True, choices=[(10, '10'), (20, '20'), (50, '50'),(100, '100')])
    # status = forms.IntegerField(required=False, label="任务状态", widget=forms.Select(attrs={"class": "config-input"},
    #                             choices=[(0,'全部'),(1,'待分配'),(2,'待处理'),(3,'处理中'),(4,'待审核'),(5,'已合格'),(6,'不合格')]))


class TaskShowForm(forms.Form):
    id = forms.IntegerField(required=False, label='任务ID', widget=forms.TextInput(attrs={"class": "config-input"}))
    project_id = forms.IntegerField(required=False, label='项目ID',
                                    widget=forms.TextInput(attrs={"class": "config-input"}))
    site_name = forms.CharField(max_length=256, required=False, label='网站名称',
                                widget=forms.TextInput(attrs={"class": "config-input"}))
    site_url = forms.CharField(max_length=256, required=False, label="网站URL",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    site_type = forms.IntegerField(required=False, label="网站类型",
                                   widget=forms.TextInput(attrs={"class": "config-input"}))
    domain = forms.CharField(max_length=128, required=False, label="域名",
                             widget=forms.TextInput(attrs={"class": "config-input"}))
    ctime = forms.IntegerField(required=False, label="录入时间",
                               widget=forms.TextInput(attrs={"class": "config-input", "id": "test3"}))
    receive_flag = forms.IntegerField(required=False, label="领取时间",
                                      widget=forms.TextInput(attrs={"class": "config-input", "id": "test4"}))
    allocation_flag = forms.IntegerField(required=False, label="分配时间",
                                         widget=forms.TextInput(attrs={"class": "config-input", "id": "test1"}))
    process_type = forms.IntegerField(required=False, label="分配代码",
                                      widget=forms.TextInput(attrs={"class": "config-input"}))
    note = forms.CharField(max_length=256, required=False, label="任务备注",
                           widget=forms.TextInput(attrs={"class": "config-input"}))
    finish_flag = forms.IntegerField(required=False, label="通过时间",
                                     widget=forms.TextInput(attrs={"class": "config-input", "id": "test2"}))
    uid = forms.IntegerField(required=False, label="用户ID", widget=forms.TextInput(attrs={"class": "config-input"}))
    lang = forms.CharField(max_length=32, required=False, label="网站语言",
                           widget=forms.TextInput(attrs={"class": "config-input"}))
    description = forms.CharField(max_length=256, required=False, label="任务描述",
                                  widget=forms.TextInput(attrs={"class": "config-input"}))
    # num_each_page = forms.ChoiceField(label="每页展示条数", widget=forms.Select(attrs={"class": 'config-input'}),
    #                         required=True, choices=[(10, '10'), (20, '20'), (50, '50'),(100, '100')])
    status = forms.IntegerField(required=False, label="任务状态", widget=forms.Select(attrs={"class": "config-input"},
                                                                                  choices=[(0, '全部'), (1, '待分配'),
                                                                                           (2, '待处理'), (3, '处理中'),
                                                                                           (4, '待审核'), (5, '已合格'),
                                                                                           (6, '不合格')]))


# {"key":"id", "name":"配置ID"},
#         {"key": "task", "name": "任务ID"},
#         {"key":"webname","name":"网站名称",},
#         {"key":"url", "name":"网站URL"},
#         {"key":"webtype", "name":"网站类型"},
#         {"key":"country", "name":"国家地区"},
#         {"key": "savename", "name": "配置名称"},
#         # {"key":"first_domain", "name":"一级域名"},
#         # {"key":"allocation_flag", "name":"分配时间"},
#         {"key":"savetime", "name":"上传时间"},
#         {"key":"last_modify_time", "name":"修改时间"},
#         #{"key":"process_type", "name":"分配代码"},
#         #{"key":"note", "name":"任务备注"},
#         # {"key":"ctime", "name":"录入时间"},
#
#         {"key":"language", "name":"网站语言"},
#         #{"key":"description", "name":"任务描述"},


class ConfigSshowForm(forms.Form):
    id = forms.IntegerField(required=False, label='配置ID', widget=forms.TextInput(attrs={"class": "config-input"}))
    task = forms.IntegerField(required=False, label='任务ID',
                              widget=forms.TextInput(attrs={"class": "config-input"}))
    webname = forms.CharField(max_length=256, required=False, label='网站名称',
                              widget=forms.TextInput(attrs={"class": "config-input"}))
    username = forms.CharField(max_length=256, required=False, label='用户名称',
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    url = forms.CharField(max_length=256, required=False, label="网站URL",
                          widget=forms.TextInput(attrs={"class": "config-input"}))
    webtype = forms.IntegerField(required=False, label="网站类型",
                                 widget=forms.TextInput(attrs={"class": "config-input"}))
    country = forms.CharField(max_length=128, required=False, label="国家地区",
                              widget=forms.TextInput(attrs={"class": "config-input"}))
    savename = forms.CharField(max_length=128, required=False, label="配置名称",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    savetime = forms.IntegerField(required=False, label="上传时间",
                                  widget=forms.TextInput(attrs={"class": "config-input", "id": "test1"}))
    last_modify_time = forms.IntegerField(required=False, label="修改时间",
                                          widget=forms.TextInput(attrs={"class": "config-input", "id": "test2"}))
    # process_type = forms.IntegerField(required=False, label="分配代码",
    #                                   widget=forms.TextInput(attrs={"class": "config-input"}))
    # note = forms.CharField(max_length=256, required=False, label="任务备注",
    #                        widget=forms.TextInput(attrs={"class": "config-input"}))
    # ctime = forms.IntegerField(required=False, label="录入时间", widget=forms.TextInput(attrs={"class": "config-input"}))
    # uid = forms.IntegerField(required=False, label="用户ID", widget=forms.TextInput(attrs={"class": "config-input"}))
    language = forms.CharField(max_length=32, required=False, label="网站语言",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    # description = forms.CharField(max_length=256, required=False, label="任务描述",
    #                               widget=forms.TextInput(attrs={"class": "config-input"}))
    # num_each_page = forms.ChoiceField(label="每页展示条数", widget=forms.Select(attrs={"class": 'config-input'}),
    #                         required=True, choices=[(10, '10'), (20, '20'), (50, '50'),(100, '100')])
    # status = forms.IntegerField(required=False, label="任务状态", widget=forms.Select(attrs={"class": "config-input"},
    #                             choices=[(0,'全部'),(1,'待分配'),(2,'待处理'),(3,'处理中'),(4,'待审核'),(5,'已合格'),(6,'不合格')]))


class ConfigSearchForm(forms.Form):
    task = forms.IntegerField(required=False, label='任务ID',
                              widget=forms.TextInput(attrs={"class": "config-input"}))
    webname = forms.CharField(max_length=256, required=False, label='网站名称',
                              widget=forms.TextInput(attrs={"class": "config-input"}))
    username = forms.CharField(max_length=256, required=False, label='用户名称',
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    url = forms.CharField(max_length=256, required=False, label="网站URL",
                          widget=forms.TextInput(attrs={"class": "config-input"}))
    savetime = forms.IntegerField(required=False, label="上传时间",
                                  widget=forms.TextInput(attrs={"class": "config-input", "id": "test1"}))
    finish_flag = forms.IntegerField(required=False, label="通过时间",
                                     widget=forms.TextInput(attrs={"class": "config-input", "id": "test2"}))


class ProjectSearchForm(forms.Form):
    project_id = forms.IntegerField(required=False, label='项目ID',
                                    widget=forms.TextInput(attrs={"class": "config-input"}))
    project_name = forms.CharField(max_length=256, required=False, label="项目名称",
                                   widget=forms.TextInput(attrs={"class": "config-input"}))
    project_number = forms.CharField(max_length=256, required=False, label="项目编号",
                                     widget=forms.TextInput(attrs={"class": "config-input"}))
    agency_name = forms.CharField(max_length=256, required=False, label="代理名称",
                                  widget=forms.TextInput(attrs={"class": "config-input"}))
    deadline_flag = forms.IntegerField(required=False, label="截止时间",
                                       widget=forms.TextInput(attrs={"class": "config-input", "id": "test3"}))
    project_quality_flag = forms.IntegerField(required=False, label="项目验收时间",
                                         widget=forms.TextInput(attrs={"class": "config-input", "id": "test1"}))
    num_each_page = forms.ChoiceField(label="每页展示条数", widget=forms.Select(attrs={"class": 'config-input'}),
                                      required=True, choices=[(10, '10'), (20, '20'), (50, '50'), (100, '100')])
    # status = forms.IntegerField(required=False, label="任务状态", widget=forms.Select(attrs={"class": "config-input"},
    #                             choices=[(0,'全部'),(1,'待分配'),(2,'待处理'),(3,'处理中'),(4,'待审核'),(5,'已合格'),(6,'不合格')]))


class AuditSearchForm(forms.Form):
    project_name = forms.IntegerField(required=False, label='项目名称',
                                      widget=forms.TextInput(attrs={"class": "config-input"}))
    site_name = forms.CharField(max_length=256, required=False, label='网站名称',
                                widget=forms.TextInput(attrs={"class": "config-input"}))
    site_url = forms.CharField(max_length=256, required=False, label="网站URL",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    username = forms.CharField(max_length=256, required=False, label="用户名",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    submit_flag = forms.IntegerField(required=False, label="提交时间",
                                     widget=forms.TextInput(attrs={"class": "config-input", "id": "test5"}))
    warehousing_flag = forms.IntegerField(required=False, label="入库时间",
                                          widget=forms.TextInput(attrs={"class": "config-input", "id": "test2"}))


class AuditRecordSearchForm(forms.Form):
    site_name = forms.CharField(max_length=256, required=False, label='网站名称',
                                widget=forms.TextInput(attrs={"class": "config-input"}))
    site_url = forms.CharField(max_length=256, required=False, label="网站URL",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    username = forms.CharField(max_length=256, required=False, label="用户名",
                               widget=forms.TextInput(attrs={"class": "config-input"}))
    changed_flag = forms.IntegerField(required=False, label="审核时间",
                                      widget=forms.TextInput(attrs={"class": "config-input", "id": "test2"}))
